package net.coding.api.test.helper.impl.professional;

import io.restassured.response.Response;
import net.coding.api.test.common.ProjectInfo;
import net.coding.api.test.enums.ProjectTypeEnum;
import net.coding.api.test.helper.BaseProjectHelper;

import static net.coding.api.test.ApiMethod.DELETE;
import static net.coding.api.test.ApiMethod.POST;
import static net.coding.api.test.TestClient.client;
import static net.coding.api.test.TestHelper.userHelper;


/**
 * Created with IntelliJ IDEA.
 * User: chenfeilong
 * Date: 2018/1/17
 * Time: 15:55
 * Description:
 */
public class ProfessionalProjectHelper implements BaseProjectHelper {
    @Override
    public Response createProject(int userIndex, int type, String name, String description, boolean gitEnabled, boolean gitReadmeEnabled
            , String gitIgnore, String gitLicense, String vcsType) {
     return    client().login(userIndex).params(getCreateProjectParams(ProjectTypeEnum.PRIVATE.getType(), name, description, gitEnabled
                , gitReadmeEnabled, gitIgnore, gitLicense, vcsType)).request(POST, "/project").response();
    }


    @Override
    public Response deleteProject(int userIndex, ProjectInfo projectInfo) {
       return client().login(userIndex).request(DELETE, String.format("/project/%d?name=%s&password=%s"
                , projectInfo.getId(), projectInfo.getName(), userHelper.getPassword(userIndex, true))).response();
    }

    @Override
    public Integer getProjectCreatorRole() {
        return 100;
    }

    @Override
    public String getProjectPath(String projectName) {
        return String.format("/u/%s/p/%s", userHelper.getGlobalKey(), projectName);
    }

    @Override
    public String getBackendProjectPath(String projectName) {
        return getProjectURI(projectName);
    }

}
